package com.coldchain;

import com.coldchain.authclient.EnableAceAuthClient;
import com.coldchain.gate.config.UserPrincipal;
import com.coldchain.gate.ratelimit.EnableAceGateRateLimit;
import com.coldchain.gate.ratelimit.config.IUserPrincipal;
import com.fangliai.core.entitiy.SystemModelEnum;
import com.spring4all.swagger.EnableSwagger2Doc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients({"com.coldchain.common.feign","com.coldchain.authclient.feign"})
@EnableZuulProxy
@EnableScheduling
@EnableAceAuthClient
@EnableAceGateRateLimit
@EnableSwagger2Doc
@EnableSwagger2
@Controller
public class GateBootstrap {
    public static void main(String[] args) {
        SpringApplication.run(GateBootstrap.class, args);
    }

    @Bean
    @Primary
    IUserPrincipal userPrincipal(){
        return new UserPrincipal();
    }

    @RequestMapping("/login/{model}")
    public String login(@PathVariable("model") String model){
        if(SystemModelEnum.CYS.name().equals(model.toUpperCase())){
            return "cyslogin";
        }
        if(SystemModelEnum.USER.name().equals(model.toUpperCase())){
            return "userlogin";
        }
        return "redirect:/404.html";
    }
}
